<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- import CSS -->
	<link rel="stylesheet" href="/css/elementui/index.css">
	<link rel="stylesheet" href="/css/exam/css/style.css">
	<link rel="stylesheet" href="/iconfont/iconfont.css">
    <!-- import Vue before Element -->
    <title>直播新增</title>
</head>

<body>
    {{ csrf_field() }}
    <!-- 直播新增 -->
    <div id="app">
        <!-- Test paper category -->
        <el-card>
            <el-page-header @back="goBack" content="直播新增">
            </el-page-header>
        </el-card>
        <!-- Classification Selection -->
        <el-card>
            <el-form :model="formData" :rules="rules" ref="formData" label-width="270px" class="demo-ruleForm">
                <el-form-item label="课件ID" prop="id" style="width: 600px;">
                    <el-input v-model="formData.id"></el-input>
                </el-form-item>
                <!-- <el-form-item label="用户ID" prop="user_id" style="width: 450px;">
                    <el-input v-model="formData.user_id"></el-input>
                </el-form-item>
                <el-form-item label="发布时间" prop="created_at" style="width: 450px;">
                    <el-input v-model="formData.created_at"></el-input>
                </el-form-item>
                <el-form-item label="跟新时间" prop="updated_at" style="width: 450px;">
                    <el-input v-model="formData.updated_at"></el-input>
                </el-form-item>
                <el-form-item label="token" prop="_token" style="width: 450px;display:none">
                    <el-input v-model="formData._token"></el-input>
                </el-form-item> -->
        </el-card>
        <el-card>
            <el-button type="primary" @click="formValidate('formData')" style="margin-left: 270px;"  v-debounce>保&ensp;&ensp;存</el-button>
            <!-- :loading="loading" -->
            <el-button @click="resetForm('formData')" style="margin-left: 40px;">重&ensp;&ensp;置</el-button>
            </el-form-item>
        </el-card>
        </el-form>
    </div>
</body>
<script src="/css/exam/js/vue.js"></script>
<script src="/css/elementui/index.js"></script>
<script src="/css/exam/js/axios.min.js"></script>
<script src="/css/exam/js/common.js"></script>
<script>
    new Vue({
        el: '#app',
        data: function() {
            return {
                formData: {
                    id: '',
                    // user_id: '',
                    // created_at: '',
                    // updated_at: '',
                    // _token: '{{csrf_token()}}',
                },
                rules: {
                    id: [{
                            required: true,
                            message: '课件ID不能为空',
                            trigger: 'blur',
                        },
                        // {
                        //     min: 2,
                        //     max: 20,
                        //     message: '长度在 2 到 60 个字符',
                        //     trigger: 'blur'
                        // }
                    ],
                    // user_id: [{
                    //     required: true,
                    //     message: '用户ID不能为空',
                    //     trigger: 'blur',
                    // }, ],
                    // created_at: [{
                    //     required: true,
                    //     message: '发布时间不能为空',
                    //     trigger: 'blur',
                    // }, ],
                    // updated_at: [{
                    //     required: true,
                    //     message: '跟新时间不能为空',
                    //     trigger: 'blur',
                    // }, ],
                    // cidData: [],
                }
            }
        },
        created() {
            // console.log('-------------->', '{{csrf_token()}}')
            // this.getciddata()
        },
        methods: {
            // getciddata() {
            //     axios.get('/admin/video/status_all?limit=' + 100, {
            //             type: this.data
            //         })
            //         .then(res => {
            //             this.cidData = res.data.data;
            //             console.log('请求成功' + res.data.data);
            //         }).catch(error => {
            //             console.log('请求失败：' + error);
            //         })
            // },
            formValidate(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        let id = this.formData.id;
                        // let user_id = this.formData.user_id;
                        // let created_at = this.formData.created_at;
                        // let updated_at = this.formData.updated_at;
                        // let _token = this.formData._token;
                        axios.post('/admin/video/push', {
                                id: id,
                                // user_id: user_id,
                                // created_at: created_at,
                                // updated_at: updated_at,
                                // _token: _token,
                            })
                            .then(res => {
                                if (res.data.code == 200) {
                                    this.$message({
                                        type: 'success',
                                        message: '保存成功！'
                                    });
                                    this.$refs[formName].resetFields();
                                    window.open("{{ route('admin.examview.live') }}", '_self')
                                } else if(res.data.code == 408){
                                    this.$message({
                                        type: 'info',
                                        message: '该名称已存在，请重新录入！'
                                    })
                                } else{
									this.$message({
									    type: 'info',
									    message: '网络原因，请稍后再试'
									})
								}
                            })
                    } else {
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
            goBack() {
                window.history.go(-1)
                console.log('go back');
            },
        }
    })
</script>

</html>